<template>
  <el-form :model="form" label-position="right" :rules="rules" label-width="140px" ref="refForm">
    <el-form-item label="项目：" prop="appType">
      <el-radio-group v-model="form.appType">
        <el-radio v-for="item in consts.APP_TYPE" :key="item.value" :label="item.value" v-if="item.value!=-1">
          {{item.title}}
        </el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="手机端类型：" prop="clientType">
      <el-radio-group v-model="form.clientType">
        <el-radio v-for="item in consts.PHONE_TYPE" :key="item.value" :label="item.value" v-if="item.value!=-1">
          {{item.title}}
        </el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="主题：" prop="name">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="内容：" prop="content">
      <!--<weditor ref="editor" v-model="form.content"></weditor>-->
      <!--<el-input-->
        <!--type="textarea"-->
        <!--:rows="2"-->
        <!--placeholder="请输入内容"-->
        <!--v-model="form.content">-->
      <!--</el-input>-->
      <Tinymce :height=400 ref="editor" v-model="form.content"/>
    </el-form-item>
    <el-form-item label="下载地址：" prop="url" :error='urlError'>
      <!--<editor-app color="#1890ff" class="editor-upload-btn"-->
      <!--:limit="1"-->
      <!--v-model="form.url"-->
      <!--@successCBK="appSuccessCBK"></editor-app>-->
      <el-input v-model="form.url" placeholder="请输入下载地址" ></el-input>
      <el-tip>下载地址只能填域名</el-tip>
    </el-form-item>
    <el-form-item label="h5地址：" prop="">
      <el-input v-model="form.h5url" placeholder="请输入h5地址"></el-input>
      <el-tip>如果配置的地址为"/introduce-sport-trust",记得传值type(1代表娱乐app，2代表体育app，3代表代理app)，如下载体育App完整地址：/introduce-sport-trust?type=2</el-tip>
    </el-form-item>
    <el-form-item label="版本号：" prop="version">
      <el-input size="small" v-model="form.version"></el-input>
    </el-form-item>
    <el-form-item label="更新类型：" prop="updateType">
      <el-radio-group v-model="form.updateType">
        <el-radio-button label="0">弱更新</el-radio-button>
        <el-radio-button label="1">强更新</el-radio-button>
        <el-radio-button label="2">掉签更新</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="发布时间：" prop="validDate">
      <el-date-picker
        v-model="form.validDate"
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择日期时间">
      </el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="toSave" size="large">确定
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import Tinymce from '@/components/Tinymce';
// import EditorApp from '@/components/Tinymce/components/editorApp'
import {
  systemAppVersionSaveApi as saveApi,
} from '@/services/api/system';
import { form, factory } from '@/build';
import weditor from '@/components/WEditor/index';
import ElTip from "@/components/Tip/index";


export default {
  name: 'appVersionNew',
  components: {
    ElTip,
    // weditor,
    Tinymce,
  },
  mixins: [form, factory],
  data() {
    return {

      form: {
        appType: 0,
        name: '',
        clientType: 3,
        content: '',
        validDate: '',
        version: '',
        url: '',
        updateType: '1',
        h5url: '',

      },
      urlError: '',
      rules: {
        appType: [{ required: true, trigger: 'blur', message: '项目为必填项' }],
        clientType: [{ required: true, trigger: 'blur', message: '手机端类为必填项' }],
        name: [{ required: true, trigger: 'blur', message: '主题为必填项' }],
        content: [],
        url: [{ validator: factory.getValidator('uri') }],
        version: [{ required: true, trigger: 'blur', message: '当前要发包的版本号为必填项' }],
        validDate: [{ required: true, trigger: 'blur', message: '发布时间为必填项' }],
        updateType: [{ required: true, trigger: 'blur', message: '更新类型为必填项' }],
      },
    };
  },
  methods: {
    onSubmit() {

    },
    toSave() {
      if (this.form.clientType != 3) {
        if (!this.form.url && this.form.url != '0') {
          this.urlError = '下载地址不能为空';
          return;
        }
      }
      this.$refs.refForm.validate((valid) => {
        if (valid) {
          this.doSave({
            action: 'saveForm',
            form: {
              name: 'refForm',
              scrollToError: true,
            },
          });
        }
      });
    },
    appSuccessCBK(res) {
      this.form.url = res.responseUrl;
    },
    // insertImg(){
    //   if (type === 'success') {
    //     var res = JSON.parse(resTxt)//不处理默认认为返回值位图片路径
    //     if (res.code !== 1) {
    //       return ;
    //     }
    //     return res.data
    //   } else if (type === 'error') {
    //     //todo toast
    //   } else if (type === 'timeout') {
    //     //todo toast
    //   }
    //   return '上传失败__'
    // },
  },
  mounted() {
    // tab页记录访问日志
    this.$store.dispatch(types.SAVE_OPERATION_LOG, { content: _.getContent(this.$route, '新建更新版本', true) });
    this.bindSave(saveApi, 'saveForm', 'form', {
      beforeSend: data => data,
      afterSuccess: () => {
        this.resetForm('refForm');
        this.form.h5url = '';
        this.form.content = undefined;
        this.$nextTick(() => {
          this.$emit('change-tab', { name: 'two' });
        });
      },
    });
  },
};
</script>

<style scoped>

</style>
